<template>
  <div id="news" class="container">
    <table-filter>
      <el-input
        placeholder="请输入公告名称"
        clearable
        v-model="apiSetting.data.name"
      ></el-input>
      <el-button plain type="warning" @click="search">查询</el-button>
    </table-filter>
    <el-row>
      <el-button plain type="primary" @click="showEaDialog = true"
        >发布公告</el-button
      >
    </el-row>
    <data-table ref="dtb" :api-setting="apiSetting" pagination>
      <!--<el-table-column
        fixed
        prop="noticeid"
        label="公告id"
        show-overflow-tooltip
      />-->
      <el-table-column
        prop="name"
        label="公告标题"
        width="300"
        show-overflow-tooltip
      />
      <el-table-column prop="content" label="公告内容" show-overflow-tooltip />
      <el-table-column
        prop="createperson"
        label="发布者"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        prop="createtime"
        label="发布时间"
        width="170"
        show-overflow-tooltip
      >
        <template slot-scope="{ row }">
          {{ row.createtime | formatterDate }}
        </template>
      </el-table-column>
      <el-table-column
        prop="state"
        label="发布状态"
        width="80"
        show-overflow-tooltip
      >
        <template slot-scope="{ row }">
          {{ row.state ? "已发布" : "草稿" }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="{ row }">
          <el-button
            @click="hasEaPermission(row.createperson, 'edit', row)"
            type="text"
            size="small"
            >编辑
          </el-button>
          <el-button
            @click="
              hasEaPermission(
                row.createperson,
                'delRow',
                `/sys/notice/delete/${row.noticeid}`,
                '公告'
              )
            "
            class="danger"
            type="text"
            size="small"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </data-table>
    <ea-news
      :show.sync="showEaDialog"
      ref="eaDialog"
      @on-reload="dtb.loadData()"
    />
  </div>
</template>

<script>
import dtb from "../../mixins/refs/dtb";
import deleteRow from "../../mixins/dataTable/deleteRow";
import EaNews from "./EaNews";
import eaDialog from "../../mixins/refs/eaDialog";
import tbSearch from "@/mixins/dataTable/tbSearch";
import permission from "@/mixins/permission/permission";

export default {
  name: "index",
  components: { EaNews },
  mixins: [permission, dtb, deleteRow, eaDialog, tbSearch],
  data() {
    return {
      apiSetting: {
        method: "post",
        url: "/sys/notice/list",
        data: {
          name: ""
        }
      }
    };
  },
  methods: {
    edit(row) {
      this.api.getNewsById(row.noticeid).then(res => {
        res.editFalse = true;
        this.showEaDialog = true;
        res.classCode = res.stuname ? res.stuname.split(",") : [];
        this.eaDialog.setEditData({
          singleData: res
        });
      });
    }
  }
};
</script>

<style scoped></style>
